#include <bits/stdc++.h>
using namespace std;

int main()
{
	int t;
	cin >> t;
	while(t--)
	{
		string s;
		cin >> s;
		long long last=0,cur=0;
		char lastchar='+';
		for(int i=0;i<s.size();i++)
		{
			if(isdigit(s[i]))
			{
				cur=0;
				while(i<s.size()&&isdigit(s[i]))
				{
					cur=cur*10+s[i]-'0';
					i++;
				}
				
				if(lastchar=='+')
				{
					last=last+cur;
				}
				else if(lastchar=='-')
				{
					last=last-cur;
				}
			}
			else if(s[i]=='+'&&s[i]=='-')
			{
				lastchar=s[i];
				continue;
			}
		}
		cout << last << endl;
	}
    return 0;
}

